//
//  SchoolsCell.m
//  EducationAdminClient
//
//  Created by KWSD on 15/12/7.
//  Copyright © 2015年 周佳兴. All rights reserved.
//

#import "SchoolsCell.h"
#import "Masonry.h"
@implementation SchoolsCell

- (void)awakeFromNib {
    // Initialization code
    [super awakeFromNib];
}

-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self) {
        UIView *view = [self createUI];
        [self.contentView addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left);
            make.right.equalTo(self.contentView.mas_right);
            make.height.equalTo(self.contentView.mas_height);
            make.bottom.equalTo(self.contentView.mas_bottom);
        }];
    }
    return self;

    
}

-(UIView *)createUI{
    UIView *baseView = [[UIView alloc]init];
    baseView.backgroundColor =[UIColor whiteColor];
    
    _seleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [baseView addSubview:_seleBtn];
    
    _titleName =[[UILabel alloc]init];
    [baseView addSubview:_titleName];
    
    [_seleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(baseView.mas_left).offset(10);
        make.width.equalTo(@(40));
        make.height.equalTo(@(40));
        make.centerY.equalTo(baseView.mas_centerY);
        
    }];
    
    [_titleName sizeToFit];
    [_titleName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_seleBtn.mas_right).offset(10);
        make.centerY.equalTo(baseView.mas_centerY);
    }];
    
    
    
    [_seleBtn setImage:[UIImage imageNamed:@"椭圆-1-拷贝-3"] forState:UIControlStateNormal];
     [_seleBtn setImage:[UIImage imageNamed:@"形状-20-拷贝"] forState:UIControlStateSelected];
    [_seleBtn addTarget:self action:@selector(seleClick:) forControlEvents:UIControlEventTouchUpInside];
    return baseView;
}

-(void)seleClick:(UIButton *)btn{
    
    if(self.one&&_lastButton&&_lastButton!=btn){
        [_seleBtn setImage:[UIImage imageNamed:@"椭圆-1-拷贝-3"] forState:UIControlStateNormal];
        _seleBtn.selected = NO;
    }
    _lastButton = btn;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
    if ([self.object respondsToSelector:self.schoolSelector]) {
        [self.object performSelector:self.schoolSelector withObject:self.indexPath];
        if(!_seleBtn.selected){
            [_seleBtn setImage:[UIImage imageNamed:@"形状-20-拷贝"] forState:UIControlStateSelected];
            _seleBtn.selected = YES;
        }
        else{
            [_seleBtn setImage:[UIImage imageNamed:@"椭圆-1-拷贝-3"] forState:UIControlStateNormal];
            _seleBtn.selected = NO;
        }

#pragma clang diagnostic pop
    }

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
